USE [dbdata]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_identificator_set_id]') AND parent_object_id = OBJECT_ID(N'[dbo].[identificators]'))
ALTER TABLE [dbo].[identificators] DROP CONSTRAINT [fk_identificator_set_id]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_identificator_uid]') AND parent_object_id = OBJECT_ID(N'[dbo].[identificators]'))
ALTER TABLE [dbo].[identificators] DROP CONSTRAINT [fk_identificator_uid]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF__identificato__dt__3A81B327]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[identificators] DROP CONSTRAINT [DF__identificato__dt__3A81B327]
END

GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF__identific__enabl__3B75D760]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[identificators] DROP CONSTRAINT [DF__identific__enabl__3B75D760]
END

GO

USE [dbdata]
GO

/****** Object:  Table [dbo].[identificators]    Script Date: 03/18/2012 21:04:09 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[identificators]') AND type in (N'U'))
DROP TABLE [dbo].[identificators]
GO

USE [dbdata]
GO

/****** Object:  Table [dbo].[identificators]    Script Date: 03/18/2012 21:04:09 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[identificators](
	[id] [bigint] IDENTITY(1,1) NOT NULL,
	[dt] [datetime] NOT NULL,
	[set_id] [int] NOT NULL,
	[uid] [int] NULL,
	[account_id] [bigint] NULL,
	[ser_id] [int] NOT NULL,
	[code_b] [varchar](900) NULL,
	[enabled] [bit] NOT NULL,
	[dt_removed] [datetime] NULL,
PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'AddOn' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'identificators', @level2type=N'COLUMN',@level2name=N'code_b'
GO

ALTER TABLE [dbo].[identificators]  WITH CHECK ADD  CONSTRAINT [fk_identificator_set_id] FOREIGN KEY([set_id])
REFERENCES [dbo].[identificator_sets] ([id])
GO

ALTER TABLE [dbo].[identificators] CHECK CONSTRAINT [fk_identificator_set_id]
GO

ALTER TABLE [dbo].[identificators]  WITH CHECK ADD  CONSTRAINT [fk_identificator_uid] FOREIGN KEY([uid])
REFERENCES [dbo].[users] ([id])
GO

ALTER TABLE [dbo].[identificators] CHECK CONSTRAINT [fk_identificator_uid]
GO

ALTER TABLE [dbo].[identificators] ADD  DEFAULT (getdate()) FOR [dt]
GO

ALTER TABLE [dbo].[identificators] ADD  DEFAULT ((0)) FOR [enabled]
GO

